import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:get/get.dart';
import 'package:laos_mall/app_route.dart';
import 'package:laos_mall/common/base/page_size_controller.dart';
import 'package:laos_mall/common/style/extension_util.dart';
import 'package:laos_mall/common/widght/image_widget.dart';
import 'package:laos_mall/common/widght/item_widget.dart';

import '../../../../common/config/app_const.dart';
import '../../../../common/style/app_style.dart';
import '../../../../common/widght/list_title_widget.dart';
import '../../widgets/number_mall_widget.dart';
import 'logic.dart';

class FaviuritesPage extends StatelessWidget {
  FaviuritesPage({Key? key}) : super(key: key);

  final logic = Get.put(FaviuritesLogic());

  @override
  Widget build(BuildContext context) {
    return GetBuilder<FaviuritesLogic>(builder: (logic) {
      return _buildCart();
    });
  }

  _buildCart() {
    return PageSizeView(itemBuilder: (context, index, data) {
      return _buildCartItem(index);
    },shrinkWrap: true, controller: logic,);
  }

  _buildCartItem(index) {
    bool isSel = false;
    var model = logic.dataSource[index];
    return Slidable(
      closeOnScroll: false,
      endActionPane: ActionPane(motion: ScrollMotion(), children: [
        SlidableAction(
          onPressed: (_) {},
          backgroundColor: Color(0xFFFE4A49),
          foregroundColor: Colors.white,
          icon: Icons.delete,
          label: 'Delete',
          padding: EdgeInsets.symmetric(vertical: 12),
        )
      ]),
      child:
      ListTitleWidget(
        maxLeadingW: 80.w,
        leading: ImageWidget(url: model.pic_thumb, fit: BoxFit.cover,)
            .addContainer(color: Colors.transparent, width: 80.w, height: 80.w),
        title: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(model.product_name).addPadding(
                EdgeInsets.only(left: 16.w)),
            Text(model.product_sku?.firstOrNull?.sku_value ?? "none".tr, style: AppStyle.subtitleLightStyle,).addPadding(
                EdgeInsets.only(left: 16.w, top: 9.h)),
          ],),
        paddingOfLeft: EdgeInsets.zero,
        showArrow: false,
      ),).addContainer(height: 80.w,
        margin: EdgeInsets.only(bottom: 20.h),
        padding: EdgeInsets.symmetric(horizontal: 20.w)).addGestureTap(() {
      Get.toNamed(AppRouter.productDetail);
    });
  }
}
